<?php
/**
 * 预约项目
 * Author: 毛康燕
 * Date: 2021/6/17
 */

namespace app\backend\controller\v1;

use app\BaseController;
use app\common\model\Subscribe as SubscribeModel;

class Subscribe extends BaseController
{
    //显示
    public function index()
    {
        $model = new SubscribeModel();
        $page = input('page/d', 1);
        $name = input('name');
        $where = [];
        if (!empty($name)) {
            $where[] = [
                ['name', 'like', "%$name%"],
            ];
        }
        $ban = $model
            ->where($where)
            ->page($page, 5)
            ->select();
        $count = $model
            ->where($where)
            ->count();
        $maxpage = ceil($count / 5);
        return sucessMsg(200, '获取成功！', ['ban' => $ban, 'maxpage' => $maxpage]);
    }

    //删除
    public function delete()
    {
        $data = input();
        $model = SubscribeModel::destroy($data['id']);
        if ($model) {
            return sucessMsg(200, '删除成功！');
        } else {
            return errMsg(500, '删除失败！');
        }
    }
}